﻿<%@ WebHandler Language="C#" Class="getHandler" %>

using System;
using System.Web;
using Libs.Content;
using System.Text;
using Newtonsoft.Json;

public class getHandler : IHttpHandler {

    StringBuilder sb = new StringBuilder();
  
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            var t = HttpContext.Current.Request.QueryString["_t"];
            switch (t)
            {
                case "getRateGold":
                    getRateGold();
                    break;        
                case "getRatio"      :
                    getRatio();
                    break;
                default:
                    sb.Append("Invalid Handler");
                    break;
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(sb.ToString());
        }

        catch (Exception ex)
        {
            Libs.Utils.NLogLogger.TraceMessage(ex.ToString());
            context.Response.ContentType = "text/plain";
            context.Response.Write(string.Empty);
        }
    }
    private void getRatio()
    {
        Ratio obj = new Ratio();
        var objRe = obj.GetList();
        sb.Append(JsonConvert.SerializeObject(objRe));
    }
 
    private void getRateGold()
    {
        GoldRate obj = new GoldRate();
        var objRe = obj.GetList();
        sb.Append(JsonConvert.SerializeObject(objRe));    
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}